class Solution1 {
    public String multiply(String num1, String num2) {
        if(num1.equals("0") || num2.equals("0")){
            return "0";
        }
        // 将字符串逆序
        char[] n1 = new StringBuffer(num1).reverse().toString().toCharArray();
        char[] n2 = new StringBuffer(num2).reverse().toString().toCharArray();
        int m = n1.length, n = n2.length;
        //临时存储
        int[] tmp = new int[m + n - 1];
        for (int i = 0; i < m; i++) {
            for(int j = 0;j < n;j++){
                tmp[i + j] += (n1[i] - '0') * (n2[j] - '0');
            }
        }

        StringBuffer ret = new StringBuffer();
        int cur = 0,t = 0;
        while(cur < m + n - 1 || t != 0){
            if(cur < m + n - 1){
                t += tmp[cur++];
            }
            ret.append((char)((char)(t % 10 )+ '0'));
            t /= 10;
        }
        ret.reverse();
        return ret.toString();
    }
}